/**
 * Author shuqi
 * Rev
 * Date: 2019-03-29 10:28
 * <p>
 * Copyright (C) 2019 Seeyon, Inc. All rights reserved.
 * <p>
 * This software is the proprietary information of Seeyon, Inc.
 * Use is subject to license terms.
 * @company seeyon.com
 * @since V5 V7.1
 * @author shuqi
 */
package com.shuqi.utils;

import com.google.gson.Gson;
import com.shuqi.tools.utils.LoggerUtils;

/**
 * @description
 * @date 2019-03-29 10:28
 * @since V5 V7.1
 * @author shuqi
 */
public class JSONUtils {
//	private static Logger logger = LoggerFactory.getLogger(JSONUtils.class);
//
//	public static ObjectMapper om  = new ObjectMapper();
//	static {
//		om.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)// json -> object 忽略多余的属性
//			.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true)
//			.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false)
//			.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true)
//			.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true)
//			.configure(JsonParser.Feature.ALLOW_MISSING_VALUES, true)
//			.configure(JsonParser.Feature.ALLOW_TRAILING_COMMA, true)
//			.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true)// String -> json 对象多一个,
//			.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true)
//			.configure(JsonGenerator.Feature.WRITE_NUMBERS_AS_STRINGS, false);
//	}
//	public static String toJson(Object o){
//		try {
//			return om.writeValueAsString(o);
//		} catch (JsonProcessingException e) {
//			logger.error("Covert Object As String Error ! ", e);
//		}
//		return "";
//	}
//
//	public static <T> T parseJson(String json,Class<T> clazz){
//		try {
//			return om.readValue(json, clazz);
//		} catch (Exception e) {
//			logger.error("Parse Json String To Object Error ! ", e);
//		}
//		return null;
//	}

		public static String toJson(Object o){
			try {
				return new Gson().toJson(o);
			} catch (Exception e) {
				LoggerUtils.error("Covert Object As String Error ! ", e);
			}
			return "";
		}

		public static <T> T parseJson(String json,Class<T> clazz){
			try {
				return new Gson().fromJson(json,clazz);
			} catch (Exception e) {
				LoggerUtils.error("Parse Json String To Object Error ! ", e);
			}
			return null;
		}

}
